﻿using Microsoft.EntityFrameworkCore.Storage;

namespace miniMana.Entity.EntityBase
{
    /// <summary>
    /// Respository接口
    /// </summary>
    public interface IRepository<T, TId> where T : IBaseEntity<TId>
    {
        /// <summary>
        /// 事务
        /// </summary>
        /// <returns></returns>
        IDbContextTransaction BeginTransaction();

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Query();

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        void Add(T entity);

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="entity"></param>
        void AddRange(IEnumerable<T> entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);

        /// <summary>
        /// 同步保存
        /// </summary>
        void Save();

        /// <summary>
        /// 异步保存
        /// </summary>
        /// <returns></returns>
        Task SaveAsync();
    }

    public interface IRepository<T> : IRepository<T, int> where T : IBaseEntity<int>
    {
    }
}
